package com.ctg.behavior.client.impala.config;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.sql.Connection;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/****************************************************************
 * CtImpala连接池配置项
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ConfigurationProperties(prefix = "ctg.impala.pool")
@Component
public class CtImpalaPoolConfig extends GenericObjectPoolConfig<Connection> {

	// MaxClientsPerIP[同一个IP允许8个链接]
	// MaxClientsNumber[最大的客户端数量]
	// 最大空闲链接数
	private int maxIdle = 3;
	// 最大链接数
	private int maxTotal = 30;
	// 当连接池资源maxTotal耗尽时，调用者最大阻塞的时间[ms] -1表示阻塞
	private long maxWaitMillis;
	// 运行一次空闲连接回收器[ms]
	private long timeBetweenEvictionRunsMillis;
	// 池中的连接空闲被回收[ms]
	private long minEvictableIdleTimeMillis;
	// 指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除
	private boolean testWhileIdle = true;

	@Override
	public int getMaxIdle() {
		return maxIdle;
	}

	@Override
	public void setMaxIdle(int maxIdle) {
		this.maxIdle = maxIdle;
	}

	@Override
	public int getMaxTotal() {
		return maxTotal;
	}

	@Override
	public void setMaxTotal(int maxTotal) {
		this.maxTotal = maxTotal;
	}

	@Override
	public long getMaxWaitMillis() {
		return maxWaitMillis;
	}

	public void setMaxWaitMillis(long maxWaitMillis) {
		this.maxWaitMillis = maxWaitMillis;
	}

	@Override
	public long getTimeBetweenEvictionRunsMillis() {
		return timeBetweenEvictionRunsMillis;
	}

	@Override
	public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
		this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
	}

	@Override
	public long getMinEvictableIdleTimeMillis() {
		return minEvictableIdleTimeMillis;
	}

	@Override
	public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
		this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
	}

	@Override
	public boolean getTestWhileIdle() {
		return testWhileIdle;
	}

	@Override
	public void setTestWhileIdle(boolean testWhileIdle) {
		this.testWhileIdle = testWhileIdle;
	}

}
